/****************************************************************************************
 Copyright © 2003-2012 ZTEsoft Corporation. All rights reserved. Reproduction or       <br>
 transmission in whole or in part, in any form or by any means, electronic, mechanical <br>
 or otherwise, is prohibited without the prior written consent of the copyright owner. <br>
 ****************************************************************************************/
package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.alibaba.fastjson.JSONObject;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.constant.ServiceOfferConsts;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalDcPublicConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.util.DateFormatUtils;
import com.iwhalecloud.bss.kite.cucc.service.pos.handler.CuccPosServiceUtils;
import com.iwhalecloud.bss.kite.cucc.service.util.ProdCateUtil;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferCache;
import com.iwhalecloud.bss.kite.dataservice.entity.DcPublic;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Offer;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.enums.ActionType;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.base.util.LocalAttrUtils;
import com.ztesoft.bss.common.bo.LoginInfo;
import com.ztesoft.bss.common.exception.BssException;
import com.ztesoft.bss.common.util.ContextUtil;
import com.ztesoft.bss.common.util.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

/**
 * <Description> <br>
 * 资费结算账户
 */

public class FeeSettlementAccountAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {
    @Autowired
    private IQuerySceneInstService querySceneInstService;
    @Override
    public void before(KiteAttr attr, KiteInst inst, String value, AttrData data) {
       super.before(attr, inst, value, data);
    }

    @Override
    public void set(KiteAttr attr, KiteInst inst, String value, AttrData data) {
        super.set(attr, inst, value, data);
    }
    @Override
    public void onShow(KiteAttr attr, KiteInst inst, AttrData data) {
        String nodeCode = querySceneInstService.getExtParameterValue(data.getSceneInstId(), "nodeCode");
        // 起租环节描述和收取方式置灰
        if (KiteStringUtils.isEqual("OrderStartRent", nodeCode)) {
            String cateId = CuccPosServiceUtils.getCateId(data.getSceneInstId(), data.getCustId());
            if(KiteStringUtils.equalsAny(cateId, ProdCateUtil.getDoubleLineOBCateIdForArr())){
                String [] controlAttrs = {"210004652","210005007","200003978","210004653","200000170","200000171"};
                for(String attrName : controlAttrs){
                    KiteAttr controlAttr = inst.getAttr(attrName);
                    if(Objects.nonNull(controlAttr)){
                        controlAttr.setIsEdit(KeyConsts.IFTRUE_F);
                    }
                }
            }
        }
        super.onShow(attr, inst, data);
    }
    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data){
        List<JSONObject> accounts =LocalAttrUtils.getInstance().qrySettlementAccount();
        List<KiteAttrValue>  attrValues= new ArrayList<>();
//        attrValues.add(attr.getAttrValues().get(0));
        for(JSONObject jo : accounts){
            KiteAttrValue kiteAttrValue = new KiteAttrValue();
            kiteAttrValue.setAttrValue(jo.getString("FLOW_ID"));
            kiteAttrValue.setAttrValueName(jo.getString("PAYER"));
            kiteAttrValue.setAttrValueDesc(jo.getString("PAYER"));
            kiteAttrValue.setAttrId(attr.getAttrId());
            kiteAttrValue.setSortBy("1");
            attrValues.add(kiteAttrValue);
        }
        attr.setAttrValues(attrValues);
        super.after(attr, inst, data);
    }



}
